<template>
	<div class="left-navigation-panel" v-loading.fullscreen.lock="loading" :elementLoadingText="$t('正在处理，请稍候...')">
		<div class="header">
			<awsui-input :placeholder="$t('搜索菜单')" v-model="searchValue" @keyup.enter="filterNavData" clearable
				@clear="clearSearcher">
				<template #prefix>
					<i class="awsui-iconfont">&#xe6e9;</i>
				</template>
			</awsui-input>
		</div>
		<div class="main" :style="{ height: mainHeight }">
			<awsui-button type="primary" icon="&#xe623;" style="width:250px;height:30px;margin:5px 0px 5px 20px;"
				@click="showDetails('add')" v-if="handleRoot">{{ $t("新建子系统") }}</awsui-button>
			<!-- 111 -->
			<el-skeleton style="width: 100%;" rows="5" :loading="treeDataLoading" animated>
				<template #template>
					<el-tree :data="skeletonTreeData" :props="defaultSkeletonProps" default-expand-all ref="skeletonTree">
						<template #default="{ node, data }">
							<span class="custom-tree-node">
								<span class="custom-tree-node-label">
									<div class="node-icon-panel">
										<el-skeleton-item variant="image" style="width: 16px; height:16px;" />
									</div>
									<div class="node-label-text-panel">
										<el-skeleton-item variant="text" style="width: 150px;height:18px;" />
									</div>
								</span>
							</span>
						</template>
					</el-tree>
				</template>
			</el-skeleton>

			<!-- 导航树 -->
			<el-tree class="navigation-tree" :load="loadNode" :data="naviagtionTreeData" :props="defaultProps" :lazy="lazy"
				node-key="id" :expand-on-click-node="false" @node-click="handleNodeClick" ref="navTree"
				:empty-text="treeEmptyText" @node-drag-start="handleDragStart" @node-drag-enter="handleDragEnter"
				@node-drag-leave="handleDragLeave" @node-drag-over="handleDragOver" @node-drag-end="handleDragEnd"
				@node-drop="handleDrop" :draggable="draggable" :allow-drop="allowDrop" :allow-drag="allowDrag"
				:default-expanded-keys="treeExpandData" v-if="updateTreeContent" v-show="!treeDataLoading" :indent="16"
				:icon-class="'el-icon-caret-right'">
				<template #default="{ node, data }">
					<span class="custom-tree-node" @mouseenter="treeNodeEnter(data)" @mouseleave="treeNodeLeave(data)"
						:class="currentNodeId == data.id ? 'active' : ''" unselectable="on" onselectstart="return false;"
						style="-moz-user-select:none;">
						<!-- 如果是"加载更多"节点，添加特殊的点击处理 -->
						<span v-if="data.label === '加载更多'" class="load-more-node" @click="handleLoadMoreClick(node, data)">
							加载更多
						</span>

						<!-- 常规节点的显示逻辑 -->
						<span v-else class="custom-tree-node-label">
							<!-- 原有节点内容 -->
							<div v-if="data.isIconFont" class="node-icon-panel">
								<i class="el-icon-edit"></i>
							</div>
							<div v-else-if="!data.isIconFont" class="node-icon-panel">
							</div>
							<div class="node-label-text-panel" :style="data.disabled ? 'color:#9C9E9E' : ''"
								:class="(data.showNodeOp) ? 'short' : 'full'" :title="node.label" v-text="escape2Html(node.label)">
							</div>
						</span>
						<!-- 操作按钮 -->
						<span class="custom-tree-btn custom-tree-node-op-panel tree-op-panel"
							v-show="data.label !== '加载更多' ? true : false">
							<i class="awsui-iconfont tree-op" @click="showDetails('add', data)" v-show="true">&#xe623;</i>
							<i class="awsui-iconfont tree-op" @click="showDetails('edit', data)"
								v-html="data.hasManagerAC ? '&#xe636;' : '&#xe72f;'"></i>

							<awsui-popover :width="540" :placement="popoverPlacement" trigger="manual" :visible="data.opPopVisible"
								:offset="0" :hide-after="0" popper-class="nav-more-poppper-class">
								<template #reference>
									<i class="awsui-iconfont tree-op" @click="opMoreClick($event, data)">&#xe719;</i>
								</template>
								<!-- 更多操作弹出框内容 -->
								<div class="tree-node-more-panel">
									<!-- ...existing code... -->
								</div>
							</awsui-popover>
						</span>
					</span>
				</template>
			</el-tree>


		</div>

		<!--侧边栏-->
		<div class="navigation-info-sidebar">
			<el-drawer :title="sidebarTitle" v-model="drawer" :destroy-on-close="true" size="60%" :append-to-body="true"
				custom-class="navigation-info-drawer">
				<div class="navigation-sidebar-main">
					<system-info ref="systemInfo" v-if="navType == 'system'" :currentNodeId="currentNodeId"
						:currentNodeName="currentNodeName" :currentNodeReadonly="currentNodeReadonly" :currentAppId="currentAppId"
						:isYijingCloud="isYijingCloud"></system-info>
					<directory-info ref="directoryInfo" v-if="navType == 'directory'" :currentNodeId="currentNodeId"
						:currentNodeName="currentNodeName" :currentNodeReadonly="currentNodeReadonly" :currentOpType="currentOpType"
						:currentAppId="currentAppId" :isYijingCloud="isYijingCloud"
						:currentSystemData="currentSystemData"></directory-info>
					<function-info ref="functionInfo" v-if="navType == 'function'" :currentNodeId="currentNodeId"
						:currentNodeName="currentNodeName" :currentNodeReadonly="currentNodeReadonly" :currentOpType="currentOpType"
						:currentAppId="currentAppId" :isYijingCloud="isYijingCloud"
						:currentSystemData="currentSystemData"></function-info>
					<NPS :npsCode="npsData" v-show="npsShowFlag"></NPS>
				</div>
				<div class="navigation-sidebar-bottom">
					<awsui-button type="primary" @click="saveNavForm" v-if="!isReadOnlyAppAuth"
						:disabled="saveBtnIsDisabled || currentNodeReadonly">{{ $t("保存") }}</awsui-button>
					<awsui-button @click="closeSidebar">{{ $t("关闭") }}</awsui-button>
				</div>
			</el-drawer>
		</div>
		<!--侧边栏结束-->

		<!--侧边栏-->
		<el-drawer :title="$t('可访问人员')" v-model="powerUserDarwer" :destroy-on-close="true" size="60%" :append-to-body="true"
			@close="closePowerUserPanel" custom-class="navigation-powerUser-drawer">
			<div class="nav-power-user-dlg-content" :style="{ height: powerUserSidebarHeight }">
				<power-user-info :navId="currentNodeId" :isYijingCloud="isYijingCloud"
					:visitAcSize="visitAcSize"></power-user-info>
			</div>
		</el-drawer>
		<!--侧边栏结束-->

	</div>
</template>

<script lang="ts">
import { defineComponent, ref, getCurrentInstance, toRefs, reactive, onMounted } from "vue";
import SystemInfo from '@/views/info/SystemInfo.vue'
import DirectoryInfo from '@/views/info/DirectoryInfo.vue'
import FunctionInfo from '@/views/info/FunctionInfo.vue'
import PowerUserInfo from '@/views/main/PowerUserInfo.vue'
export default defineComponent({
	name: "LeftNavigation",
	components: { SystemInfo, DirectoryInfo, FunctionInfo, PowerUserInfo },
	props: {
		hasManagerAC: {
			type: Boolean
		},
		isSubAdmin: {
			type: Boolean
		},
		currentAppId: {
			type: String
		},
		isYijingCloud: {
			type: Boolean
		},
		visitAcLength: {
			type: Number
		},
		currentNavId: {
			type: String
		},
	},
	setup(props: any, ctx: any) {
		const instance = getCurrentInstance(), globalProperties = instance?.appContext.config.globalProperties,
			awsuiTools = globalProperties?.awsuiTools,
			storeData = globalProperties?.$store.state, { proxy: $this }: any = instance;
		const settingParam = instance?.appContext.config.globalProperties.AWSPageContext?.settingParam;
		const state: any = reactive({});
		const methods = {}


		return {
			...toRefs(state),
			...methods,
			// loadNode
		}
	},
	data() {
		var naviagtionTreeData: any = ref([]);//树--数据
		return {
			isDragging: false, // 是否正在拖拽
			dropSuccess: false, // 拖拽是否成功
			dragNodeData: null,     // 拖拽的节点数据
			sourceParentNode: null, // 拖拽节点的原始父节点
			// 新增：拖拽意图相关状态
			pendingDragOperation: null, // 待确认的拖拽操作
			isWaitingForConfirmation: false, // 是否正在等待用户确认

			// 真实的树数据状态管理
			realTreeData: {
				1: { id: 1, label: '父节点1', isLeaf: false, allowDrag: true, total: 6, children: [] },
				2: { id: 2, label: '父节点2', isLeaf: false, allowDrag: true, total: 1, children: [] },
				3: { id: 3, label: '父节点3', isLeaf: false, allowDrag: true, total: 20, children: [] },
				4: { id: 4, label: '父节点4', isLeaf: true, allowDrag: true, total: 10, children: [] },
				5: { id: 5, label: '父节点5', isLeaf: false, allowDrag: true, total: 32, children: [] }
			},
			// 节点的父子关系
			nodeParentMap: {
				1: 'root',
				2: 'root',
				3: 'root',
				4: 'root',
				5: 'root'
			},
			// 根节点的子节点列表
			rootChildren: [1, 2, 3, 4, 5],
			// 节点排序映射，用于同级拖拽排序
			nodeOrder: {},

			mainHeight: "calc(100vh - 35px - 10px - 65px)",
			updateTreeContent: true,
			canSearchFlag: true,
			treeDataLoading: true,
			skeletonTreeData: [{
				id: "01", label: 'XXXXXX',
				children: [{
					id: "0101", label: 'XXXXXX',
					children: [{
						id: "010101", label: 'XXXXXX'
					}, {
						id: "010102", label: 'XXXXXX'
					}]
				}]
			}, {
				id: "02", label: 'XXXXXX',
				children: [{
					id: "0201", label: 'XXXXXX'
				}, {
					id: "0202", label: 'XXXXXX'
				}]
			}, {
				id: "03", label: 'XXXXXX',
				children: [{
					id: "0301", label: 'XXXXXX'
				}, {
					id: "0302", label: 'XXXXXX'
				}]
			}, {
				id: "04", label: 'XXXXXX'
			}, {
				id: "05", label: 'XXXXXX',
				children: [{
					id: "0501", label: 'XXXXXX',
					children: [{
						id: "050101", label: 'XXXXXX'
					}, {
						id: "050102", label: 'XXXXXX'
					}]
				}]
			}, {
				id: "06", label: 'XXXXXX'
			}, {
				id: "07", label: 'XXXXXX',
				children: [{
					id: "0701", label: 'XXXXXX'
				}, {
					id: "0702", label: 'XXXXXX'
				}]
			}, {
				id: "08", label: 'XXXXXX'
			}, {
				id: "09", label: 'XXXXXX'
			}, {
				id: "10", label: 'XXXXXX'
			}],
			defaultSkeletonProps: {
				children: 'children',
				label: 'label',
				isLeaf: "leaf",
			},
			dialogVisible: false,
			defaultProps: {
				children: 'children',
				isLeaf: 'isLeaf',
				label: 'label'
			},
			lazy: true,
			draggable: this.handleRoot,// 先设为 true 测试是否能触发拖拽  原来this.handleRoot,
			searchValue: '',
			afterSearch: false,
			title: '',
			isReadOnlyAppAuth: false,
			hasManagerAC: this.hasManagerAC,
			isSubAdmin: this.isSubAdmin,
			drawer: false,
			powerUserDarwer: false,
			navType: 'system',
			sidebarTitle: '',
			sidebarHeight: (document.documentElement.clientHeight) - 54 - 48 + 'px',//侧边栏高度
			powerUserSidebarHeight: (document.documentElement.clientHeight) - 54 + 'px',//侧边栏高度
			currentSystemData: '',
			currentNodeType: '',
			currentNodeId: "",
			currentNodeName: "",
			currentNodeSort: "10",
			currentNodeVisiable: true,
			currentOpType: "add",
			currentIcon16: "",
			currentNodeReadonly: false,
			currentNodeHasChildren: false,
			showNodeOp: false,
			naviagtionTreeData: JSON.parse(JSON.stringify(naviagtionTreeData.value)),
			naviagtionTreeDataClone: [],
			navigationIconOptions: {
				type: "background", //必传，type为"background"时，改变背景颜色，图标颜色固定，type为"icon"时改变图标颜色，背景颜色固定
				iconfontArray: window.iconfontArray, //必传，iconfont可选项数组
				fatherWidth: 80,
				width: 333,
				showFlatType: true,
			},
			navigationIconVal: "&#xe719;",
			saveBtnIsDisabled: false,
			opNodeVisiable: this.currentNodeVisiable,
			defaultIconPickerOptions: {
				type: "background", //必传，type为"background"时，改变背景颜色，图标颜色固定，type为"icon"时改变图标颜色，背景颜色固定
				//icon: "&#xe614;",  //图标
				//color: "#f2f2f2", //颜色
				show: true, //是否直接显示，不通过点击
				/*customClass: '' //自定义类名*/

			},
			iconColors: {
				icon: "",
				color: ""
			},
			isMoving: false,
			oldBlurName: "",
			oldBlurSort: "",
			currentAppId: this.currentAppId,
			treeExpandData: [],
			doNotCloseOpPop: false,
			handleRoot: this.hasManagerAC || this.isSubAdmin,
			popoverPlacement: "bottom",
			treeEmptyText: this.$t('暂无数据'),
			popperOptions: { boundariesElement: 'viewport', removeOnDestroy: true },
			loading: false,
			isYijingCloud: this.isYijingCloud,
			visitAcSize: this.visitAcLength,
			npsData: "NPS20502",
			npsShowFlag: false,
			isHighSecurity: settingParam.isHighSecurity,
			isSystemMaster: settingParam.isSystemMaster,
			isSecurityMaster: settingParam.isSecurityMaster,
			warningInfo: [
				this.$t("确定要删除该节点吗？"), this.$t("删除后该节点及其子节点将一并被删除"), this.$t("确定要移动吗？")
			],
			confirmTitle: this.$t('提示'),
			confirmOk: this.$t('确定'),
			confirmCancel: this.$t('取消'),
			deleteSuccess: this.$t('删除成功'),
			opSuccess: this.$t('操作成功'),
			moveSuccess: this.$t('移动成功'),
			updateSuccess: this.$t('修改成功'),
			saveSuccess: this.$t('保存成功'),
			nodeMessage: [this.$t("名称不允许为空"), this.$t("显示顺序不允许为空且必须为数字"), this.$t("显示顺序不允许大于30000")],
			subAdminTitle: this.$t('二级管理员'),
			searchingText: this.$t('搜索中...'),
			noDataText: this.$t('暂无数据'),
			navTitle: [
				this.$t("子系统"), this.$t("目录"), this.$t("菜单")
			],
			newSystem: this.$t("新建子系统"),
			updateSystem: this.$t("修改子系统"),
			updateDirectory: this.$t("修改目录"),
			updateFunction: this.$t("修改菜单"),
			opType: [
				this.$t("新建"), this.$t("修改")
			],


		}
	},
	mounted() {
		this.handleRoot = this.hasManagerAC || this.isSubAdmin;
		if (this.isHighSecurity && this.isSecurityMaster) {
			this.handleRoot = false;
		}
		this.draggable = this.handleRoot;
		if (this.currentNavId != "") {
			this.showDetailsForSearch();
		}


		if (this.isHighSecurity && !this.showMobileEntry) {
			this.mainHeight = "calc(100vh - 35px - 10px - 15px)";
		} else {
			this.mainHeight = "calc(100vh - 35px - 10px - 65px)";
		}

	},
	watch: {
		searchValue(val) {
			let that = this;
		},
		isSubAdmin(val) {
			this.handleRoot = val || this.hasManagerAC;
			this.draggable = this.handleRoot;
		},
		hasManagerAC(val) {
			this.handleRoot = val || this.isSubAdmin;
			this.draggable = this.handleRoot;
		},
		visitAcLength(val) {
			this.visitAcSize = val;
		}
	},
	methods: {
		showDetailsForSearch() {
			let $this = this;
			let that = this;
			let type = "";
			if (this.currentNavId.startsWith("s_")) {
				type = "system";
			} else if (this.currentNavId.startsWith("d_")) {
				type = "directory";
			} else if (this.currentNavId.startsWith("f_")) {
				type = "function";
			}
			let data = {
				url: 'jd',
				data: {
					cmd: 'CONSOLE_P_NAV_DESIGN_DETAIL_INFO',
					sid: settingParam.sessionId,
					type: type,
					id: that.currentNavId
				}
			};
		},
		onlyNumber() {
			this.currentNodeSort = this.currentNodeSort.replace(/[^\d]/g, '');
		},
		escape2Html(str) {
			str = (str == undefined) ? '' : str;
			//转义字符转换普通字符的方法
			var arrEntities = { 'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"' };
			return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function (all, t) {
				return arrEntities[t];
			});
		},
		handleIconFont() {
			this.currentIcon16 = this.iconColors.icon + "|" + this.iconColors.color;
			this.navSaveAttributeData("info");
		},
		getIconPickerStatus(val) {
		},
		loadSystemData() {
			const that = this;
			const data = {
				url: 'jd',
				data: {
					cmd: 'com.awspaas.user.apps.apptest_treeSons',
					sid: settingParam.sessionId,
					node: "root",
					appId: that.currentAppId
				}
			};
		},
		reloadParentNodeData(pid) {
			const that = this;
			const data = {
				url: 'jd',
				data: {
					cmd: 'com.awspaas.user.apps.apptest_treeSons',
					sid: settingParam.sessionId,
					node: pid,
					appId: that.currentAppId,
					searchValue: that.searchValue,
				}
			};
		},
		addSortFlag(data) {
			let $this = this;
			data.forEach(function (item, i) {
				let isFirst = false;
				let isEnd = false;
				let prevNodeId = "";
				let nextNodeId = "";
				try {
					if (data.length > 1) {
						if (i == 0) {
							isFirst = true;
							nextNodeId = data[i + 1].id;
						} else if (i + 1 == data.length) {
							isEnd = true;
							prevNodeId = data[i - 1].id;
						} else {
							prevNodeId = data[i - 1].id;
							nextNodeId = data[i + 1].id;
							data[i + 1].id;
						}
					} else {
						isFirst = true;
						isEnd = true;
					}
				} catch (e) {
				}
				item.isFirst = isFirst;
				item.isEnd = isEnd;
				item.prevNodeId = prevNodeId;
				item.nextNodeId = nextNodeId;
				item.opPopVisible = false;
				// 添加允许拖拽的标志
				// item.allowDrag = true; // 先设为 true 进行测试
				if ($this.isHighSecurity && $this.isSecurityMaster) {
					item.hasManagerAC = false;
				}
			});
			return data;
		},		//树节点懒加载
		loadNode(node: any, resolve: any) {
			let that = this;
			that.treeDataLoading = false;//骨架屏隐藏

			if (node.level === 0) {
				// 获取根目录 - 根据 realTreeData 的当前状态返回
				setTimeout(() => {

					// 根据 realTreeData 生成根节点列表
					const rootNodes = [];

					// 检查每个节点是否应该在根级显示
					for (const nodeId in that.realTreeData) {
						const nodeData = that.realTreeData[nodeId];
						// 同时检查数字和字符串键
						let parentId = that.nodeParentMap[nodeId] || that.nodeParentMap[Number(nodeId)];
						

						// 如果节点的父节点是 'root'，则添加到根节点列表
						if (parentId === 'root') {
							rootNodes.push({
								id: nodeData.id,
								label: nodeData.label,
								isLeaf: nodeData.isLeaf,
								allowDrag: nodeData.allowDrag,
								total: nodeData.total,
							});
						} else {
							console.log(`loadNode: 节点 ${nodeId} 的父节点是 ${parentId}，不在根级显示`);
						}
					}

					
					// 根据 nodeOrder 排序
					if (that.nodeOrder && Object.keys(that.nodeOrder).length > 0) {
						rootNodes.sort((a, b) => {
							const orderA = that.nodeOrder[String(a.id)] || 0;
							const orderB = that.nodeOrder[String(b.id)] || 0;
							return orderA - orderB;
						});
					}
					
					resolve(rootNodes);

					// 下面模拟加载完成后的处理逻辑
					that.$nextTick().then(() => {
						that.treeDataLoading = false; // 骨架屏隐藏
					});
				}, 500);
				return
			} else if (node.data.label !== '加载更多') {
				// 子节点数据加载
				const parentId = node.data.id;
				const page = node.data.pagination?.currentPage || 1;
				const pageSize = 10;
				const totalItems = node.data.total || 0;

				const pageSize = 10; // 每页显示10条数据
				const totalItems = node.data.total || 0; // 获取父节点声明的总子节点数
				// 模拟请求数据
				setTimeout(() => {

					const childNodes = [];

					// 检查 realTreeData 中是否有子节点
					for (const nodeId in that.realTreeData) {
						const nodeData = that.realTreeData[nodeId];
						// 同时检查数字和字符串键的父节点映射
						let nodeParentId = that.nodeParentMap[nodeId] || that.nodeParentMap[Number(nodeId)];


						// 如果节点的父节点是当前节点，则添加到子节点列表
						if (nodeParentId == parentId || String(nodeParentId) === String(parentId)) {
							console.log(`loadNode: 为父节点 ${parentId} 加载子节点 ${nodeId}`);
							childNodes.push({
								id: nodeData.id,
								label: nodeData.label,
								isLeaf: nodeData.isLeaf,
								allowDrag: nodeData.allowDrag,
								total: nodeData.total,
							});
						}
					}
					
					console.log(`loadNode: 父节点 ${parentId} 找到 ${childNodes.length} 个子节点`);

					// 如果没有找到子节点，生成一些模拟数据（原有逻辑）
					// 只有在没有找到任何子节点时才生成模拟数据
					if (childNodes.length === 0) {
						console.log(`loadNode: 父节点 ${parentId} 没有找到子节点，生成模拟数据`);
						const remainingItems = totalItems - ((page - 1) * pageSize);
						const itemsToLoad = Math.min(pageSize, Math.max(0, remainingItems));

						for (let i = 0; i < itemsToLoad; i++) {
							const childId = `${parentId}-${(page - 1) * pageSize + i + 1}`;
							const childData = {
								id: childId,
								label: `子节点${childId}页数${page}`,
								isLeaf: false,
								allowDrag: true,
								total: 13
							};
							childNodes.push(childData);
							
							// 将生成的子节点添加到 realTreeData 和 nodeParentMap 中
							that.realTreeData[childId] = childData;
							that.nodeParentMap[childId] = parentId;
							console.log(`loadNode: 添加子节点 ${childId} 到 realTreeData，父节点: ${parentId}`);
						}

						// 检查是否需要显示"加载更多"按钮
						const loadedCount = (page - 1) * pageSize + childNodes.length;
						if (totalItems > 0 && loadedCount < totalItems) {
							const loadMoreId = `${parentId}-load-more`;
							childNodes.push({
								id: loadMoreId,
								label: '加载更多',
								isLeaf: true,
								pagination: {
									currentPage: page + 1,
									pageSize,
									totalLoaded: loadedCount,
									totalCount: totalItems,
								},
							});
						}
					}

					
					// 根据 nodeOrder 排序
					if (that.nodeOrder && Object.keys(that.nodeOrder).length > 0) {
						console.log(`loadNode: 父节点 ${parentId} 应用排序规则`, that.nodeOrder);
						childNodes.sort((a, b) => {
							const orderA = that.nodeOrder[String(a.id)] || 0;
							const orderB = that.nodeOrder[String(b.id)] || 0;
							console.log(`loadNode: 排序比较 ${a.id}(${orderA}) vs ${b.id}(${orderB})`);
							return orderA - orderB;
						});
					} else {
						console.log(`loadNode: 父节点 ${parentId} 没有排序规则，使用默认顺序`);
					}
					
					console.log(`loadNode: 父节点 ${parentId} 最终返回子节点顺序`, childNodes.map(n => n.id));
					resolve(childNodes);
				}, 1000);
			} else if (node.data.label === '加载更多') {//待完善
				const parentNode = node.parent;
				const { currentPage, pageSize, totalCount } = node.data.pagination || {};
				// return
				setTimeout(() => {
					// 1. 确保父节点的children是一个有效的数组
					if (!parentNode.childNodes) {
						parentNode.childNodes = [];
					}

					// 2. 正确过滤出不包含"加载更多"的节点
					let childrenArrRel = parentNode.childNodes?.filter((child: any) => child.label !== '加载更多');
					// 输出调试信息，查看过滤后的数组
					let childrenArr: any = []
					childrenArrRel.forEach((item: any) => {
						childrenArr.push(item.data)
					})

					// 3. 计算已加载的节点总数，用于为新节点分配正确的ID
					const totalLoaded = childrenArr.length;
					const remainingItems = totalCount - totalLoaded;
					const itemsToLoad = Math.min(pageSize, Math.max(0, remainingItems));
					// 4. 准备新的节点数据----替代接口返回数据
					const newNodes = Array.from({ length: itemsToLoad }, (_, index) => ({
						id: `${parentNode.data.id}-${totalLoaded + index + 1}`,
						label: `子节点${parentNode.data.id}-${totalLoaded + index + 1}页数${currentPage}`,
						isLeaf: false,
						total: 13
					}));

					// 5. 将新节点添加到过滤后的子节点数组中childrenArr
					childrenArr = [...childrenArr, ...newNodes]
					// 6. 如果有更多数据，添加新的"加载更多"节点
					// 判断是否需要继续添加"加载更多"节点
					const newTotalLoaded = totalLoaded + newNodes.length;
					// 如果新加载的总数小于总数，则添加"加载更多"
					if (newTotalLoaded < totalCount) {
						childrenArr.push({
							id: `${parentNode.data.id}-load-more-${currentPage + 1}`,
							label: `加载更多`,
							isLeaf: true,
							pagination: {
								currentPage: currentPage + 1,
								pageSize,
								totalLoaded: newTotalLoaded,
								totalCount,
							},
						});
					}



					// 7. 更新父节点的children
					if (!Array.isArray(parentNode.data.children)) {
						parentNode.data.children = [];
					}
					parentNode.data.children.length = 0;
					parentNode.data.children.push(...childrenArr);

					// 8. 移除当前 Load More 节点
					parentNode.removeChild(node);

					// 9. 刷新树视图
					that.$nextTick(() => {
						(that.$refs.navTree as any).updateKeyChildren(parentNode.data.id, childrenArr);
					});

					resolve([]);
				}, 1000);
			}
		},
		clearSearcher() {
			this.searchValue = "";
			this.filterNavData();
		},
		filterNavData() {
			let $this = this;
			let that = this;
			if (!that.canSearchFlag) {
				return false;
			}
			that.canSearchFlag = false;
			that.treeEmptyText = that.searchingText;
			that.naviagtionTreeData = [];
			that.treeExpandData = [];
			let data = {
				url: 'jd',
				data: {
					cmd: 'CONSOLE_P_NAV_DESIGN_TREE_SEARCH_DATA',
					sid: settingParam.sessionId,
					searchValue: that.searchValue,
					appId: that.currentAppId,
				}
			};
		},
		reloadTreeContent() {
			let $this = this;
			let that = this;
			that.updateTreeContent = false;
			// 在组件移除后，重新渲染组件
			that.$nextTick(() => {
				that.updateTreeContent = true;
			});
		},
		findAllNodeIds(node, ids = []) {
			let $this = this;
			let that = this;
			if (node.id) {
				ids.push(node.id);
			}
			that.naviagtionTreeData.forEach(function (item, i) {

				ids.push(item.id);
				let itemChildren = item.children;
				if (itemChildren) {
					itemChildren.forEach(function (itemsub, isub) {
						ids.push(itemsub.id);
						let itemSubChildren = itemsub.children;
						if (itemSubChildren) {
							itemSubChildren.forEach(function (sub, isub) {
								ids.push(sub.id);
							});
						}
					});
				}
			});
			return ids;
		},
		initTreeCheck() {// 初始化树选中节点
		},
		handleNodeClick(data) {
			let $this = this;
			let that = this;
			let firstNode = document.querySelector('.navigation-tree .el-tree-node');
			if ((firstNode != null && firstNode != undefined) && firstNode.className.indexOf("is-current") != -1) {
				firstNode.className = firstNode.className.replace("is-current", "")
			}

			that.$emit('treeNodeClick', data, -1);
			/*
			if (that.searchValue != "") {
				that.showDetails('edit', data);
			}
			*/
		},
		reloadTreeNode() {
			this.loadSystemData();
		},
		hideNavigationDataOpVisiable() {
			let $this = this;
			let that = this;
			if (that.doNotCloseOpPop) {
				that.doNotCloseOpPop = false;
				return false;
			}
		},
		resetNodeData() {
			this.currentNodeVisiable = false;
			this.currentNodeId = "";
			this.currentNodeName = "";
			this.currentNodeType = "";
			this.currentNodeSort = 0;
			this.currentNodeHasChildren = false;
			this.currentSystemData = {};
		},
		showDetails(opType, navData) {
			if (navData == undefined) {
				this.sidebarTitle = this.newSystem;
				this.navType = "system";
				this.currentNodeReadonly = false;
				this.resetNodeData();
			} else {
				let id = navData.id;
				let type = navData.type;
				let name = navData.name;
				let opTypeStr = "";
				if (opType == "add") {
					opTypeStr = this.opType[0];
					this.resetNodeData();
				} else if (opType == "edit") {
					opTypeStr = this.opType[1];
					this.currentNodeId = id;
					this.currentNodeName = name;
					this.currentNodeType = type;
					this.currentNodeVisiable = navData.isActivity;
					this.currentNodeSort = navData.attributes ? navData.attributes.orderIndex : 0;
					this.currentNodeReadonly = !navData.hasManagerAC;
					this.currentNodeHasChildren = navData.leaf ? navData.leaf : false;

				}
				let typeStr = "";
				if (opType == "add") {
					if (type == "system") {
						typeStr = this.navTitle[1];
						this.navType = "directory";
						this.currentSystemData = navData;
					} else if (type == "directory") {
						typeStr = this.navTitle[2];
						this.navType = "function";
						let node = this.$refs.navTree.getNode(navData.pid);
						this.currentSystemData = node.data;
					}
					this.currentNodeId = id;
					this.currentNodeName = name;
					this.currentOpType = "add";
					this.sidebarTitle = opTypeStr + typeStr;
				} else if (opType == "edit") {
					if (type == "system") {
						typeStr = this.navTitle[0];
						this.navType = "system";
					} else if (type == "directory") {
						typeStr = this.navTitle[1];
						this.navType = "directory";
					} else if (type == "function") {
						typeStr = this.navTitle[2];
						this.navType = "function";
					}
					this.currentOpType = "update";
					this.sidebarTitle = opTypeStr + typeStr + " - " + this.escape2Html(name);
				}
			}
			this.drawer = true;
			this.saveBtnIsDisabled = false;
			this.npsShowFlag = false;
		},
		opMoreClick(event, data) {
			let $this = this;
			let that = this;
			let el = event.currentTarget;
			// 添加切换逻辑：如果当前是可见状态，点击后隐藏并返回
			if (data.opPopVisible) {
				data.opPopVisible = false;
				return;
			}
			//https://blog.csdn.net/gz_ok/article/details/106521747
			// 获取元素到页面可视区域底部的距离
			let bottomH = window.innerHeight - event.target.getBoundingClientRect().y - event.target.getBoundingClientRect().height;
			if (bottomH < 325) {
				that.popoverPlacement = "top";
				let topH = event.target.getBoundingClientRect().y;
				let left = event.target.getBoundingClientRect().left;
				if (topH < 325) {
					//上面显示不全
					that.popoverPlacement = "right";
				}
			} else {
				that.popoverPlacement = "bottom";
			}
			if (data.type != undefined) {
				//data.showNodeOp = true;
				that.currentNodeId = data.id;
				that.currentNodeName = that.escape2Html(data.name);
				that.currentNodeType = data.type;
				that.currentNodeVisiable = data.isActivity;
				that.currentNodeSort = data.attributes.orderIndex;
				that.opNodeVisiable = data.isActivity;
				that.currentNodeReadonly = !data.hasManagerAC;
				that.currentNodeHasChildren = !data.leaf;
			}


			data.opPopVisible = true;
			that.isMoving = false;//上移下移处理重复点击  在popover显示时重置下状态
			data.updateIconPicker = true;
			if (data.isIconFont) {
				that.currentIcon16 = data.iconFont.code + "|" + data.iconFont.color;
				that.updateIconPickerOption(data);
			} else {
				that.currentIcon16 = data.icon16;
				//that.resetIconPickerOption(data);
			}
			//blur时是否修改
			that.oldBlurName = that.currentNodeName;
			that.oldBlurSort = that.currentNodeSort;

		},
		closeSidebar() {
			let $this = this;
			let that = this;
			that.drawer = false;
			that.resetNodeData();
			that.npsShowFlag = false;
		},
		saveNavForm() {
			if (this.navType == 'system') {
				this.$refs.systemInfo.validForm(() => {
					this.saveSystemInfo();
				});
			} else if (this.navType == 'directory') {
				this.$refs.directoryInfo.validForm(() => {
					this.saveDirectoryInfo();
				});
			} else if (this.navType == 'function') {
				this.$refs.functionInfo.validForm(() => {
					this.saveFunctionInfo();
				});
			}
		},
		saveSystemInfo() {
			let $this = this;
			let that = this;
			var systemInfo = this.$refs.systemInfo.SystemInfo;
			var id = systemInfo.id;
			if (id.startsWith("s_")) {
				id = id.substr(2);
			}
			var systemName = systemInfo.name;
			var icon16 = systemInfo.icon16IconFont;
			var icon64 = systemInfo.icon64;
			var icon96 = systemInfo.icon96;
			var linkUrl = systemInfo.linkUrl;
			var workTarget = systemInfo.target;
			var isHidden = systemInfo.isHidden;
			var isActivity = systemInfo.isActivity;
			var navDesc = systemInfo.desc;
			var appid = systemInfo.appId;
			var notifier = systemInfo.notifier;
			var orderIndex = systemInfo.orderIndex;
			var ext1 = systemInfo.ext1;
			var ext2 = systemInfo.ext2;
			var ext3 = systemInfo.ext3;
			var ext4 = systemInfo.ext4;
			var ext5 = systemInfo.ext5;
			
			if (id != "" && appid == "" && id != "obj_00093403df6a17ed729913d64f48f930") {
				that.$message({ type: 'warning', message: '请设置归属应用' });
				return false;
			}
			that.saveBtnIsDisabled = true;
			let data = {
				url: 'jd',
				data: {
					cmd: 'CLIENT_P_NAV_DESIGN_SYSTEM_SAVE',
					sid: settingParam.sessionId,
					id: id,
					systemName: systemName,
					icon16: icon16,
					icon64: icon64,
					icon96: icon96,
					linkUrl: linkUrl,
					workTarget: workTarget,
					isHidden: isHidden,
					isActivity: isActivity,
					navDesc: navDesc,
					appid: appid,
					notifier: notifier,
					orderIndex: orderIndex,
					ext1: ext1,
					ext2: ext2,
					ext3: ext3,
					ext4: ext4,
					ext5: ext5,
				}
			};
		},
		refreshTreeNode(op, type, nodeData) {
			let $this = this;
			let that = this;
			let id = nodeData.id;
			let name = nodeData.name;
			let pid = nodeData.pid;
			let isIconFont = nodeData.isIconFont;
			let icon16 = nodeData.icon16;
			let iconFontCode = nodeData.iconFontCode;
			let iconFontColor = nodeData.iconFontColor;
			let disabled = nodeData.disabled;

			if (type == "system") {
				if (op == "add") {
					//新建子系统刷新整个树
					that.loadSystemData();
				} else if (op == "update") {
					//修改子系统 更新图标名字等
					let node = that.$refs.navTree.getNode(id);
					if (node != null) {
						node.data.name = name;
						node.data.isIconFont = isIconFont;
						node.data.iconFont.color = iconFontColor;
						node.data.iconFont.code = iconFontCode;
						node.data.icon16 = icon16;
						if (disabled != undefined) {
							node.data.disabled = disabled;
							node.data.isActivity = !disabled;
							//disabled同步到子级
							let itemChildren = node.data.children;
							if (itemChildren) {
								that.reloadParentNodeData(id);
							}
						}
					}
				}
			} else if (type == "directory") {
				if (op == "add") {
					//新建目录 重新加载某个子系统
					that.reloadParentNodeData(pid);
				} else if (op == "update") {
					//修改目录 更新图标名字等
					let node = that.$refs.navTree.getNode(id);
					if (node != null) {
						node.data.name = name;
						node.data.isIconFont = isIconFont;
						node.data.iconFont.color = iconFontColor;
						node.data.iconFont.code = iconFontCode;
						node.data.icon16 = icon16;
						if (disabled != undefined) {
							node.data.disabled = disabled;
							node.data.isActivity = !disabled;
							//disabled同步到子级
							let itemChildren = node.data.children;
							if (itemChildren) {
								that.reloadParentNodeData(id);
							}
						}
					}
				}
			} else if (type == "function") {
				if (op == "add") {
					//新建功能 重新加载某个功能
					that.reloadParentNodeData(pid);
				} else if (op == "update") {
					//修改功能 更新图标名字等
					let node = that.$refs.navTree.getNode(id);
					if (node != null) {
						node.data.name = name;
						node.data.isIconFont = isIconFont;
						node.data.iconFont.color = iconFontColor;
						node.data.iconFont.code = iconFontCode;
						node.data.icon16 = icon16;
						if (disabled != undefined) {
							node.data.disabled = disabled;
							node.data.isActivity = !disabled;
						}
					}
				}
			}
		},
		saveDirectoryInfo() {
			let $this = this;
			let that = this;
			var directoryInfo = this.$refs.directoryInfo.DirectoryInfo;
			var id = directoryInfo.id;
			if (id.startsWith("d_")) {
				id = id.substr(2);
			}
			var systemId = directoryInfo.systemId;
			var directoryName = directoryInfo.name;
			var icon16 = directoryInfo.icon16IconFont;
			var icon64 = directoryInfo.icon64;
			var icon96 = directoryInfo.icon96;
			var linkUrl = directoryInfo.linkUrl;
			var workTarget = directoryInfo.target;
			var isHidden = directoryInfo.isHidden;
			var isActivity = directoryInfo.isActivity;
			var navDesc = directoryInfo.desc;
			var appid = directoryInfo.appId;
			var notifier = directoryInfo.notifier;
			var orderIndex = directoryInfo.orderIndex;
			var ext1 = directoryInfo.ext1;
			var ext2 = directoryInfo.ext2;
			var ext3 = directoryInfo.ext3;
			var ext4 = directoryInfo.ext4;
			var ext5 = directoryInfo.ext5;
			if (id != "" && appid == "") {
				that.$message({ type: 'warning', message: '请设置归属应用' });
				return false;
			}
			that.saveBtnIsDisabled = true;
			let data = {
				url: 'jd',
				data: {
					cmd: 'CLIENT_P_NAV_DESIGN_DIRECTORY_SAVE',
					sid: settingParam.sessionId,
					directoryId: id,
					systemId: systemId,
					directoryName: directoryName,
					icon16: icon16,
					icon64: icon64,
					icon96: icon96,
					directoryUrl: linkUrl,
					directoryTarget: workTarget,
					isHidden: isHidden,
					isActivity: isActivity,
					navDesc: navDesc,
					appid: appid,
					notifier: notifier,
					orderIndex: orderIndex,
					ext1: ext1,
					ext2: ext2,
					ext3: ext3,
					ext4: ext4,
					ext5: ext5,
				}
			};
		},
		saveFunctionInfo() {
			let $this = this;
			let that = this;
			var functionInfo = this.$refs.functionInfo.FunctionInfo;
			var id = functionInfo.id;
			if (id.startsWith("f_")) {
				id = id.substr(2);
			}
			var systemId = functionInfo.systemId;
			var directoryId = functionInfo.directoryId;
			var functionName = functionInfo.name;
			var icon16 = functionInfo.icon16IconFont;
			var icon64 = functionInfo.icon64;
			var icon96 = functionInfo.icon96;
			var linkUrl = functionInfo.linkUrl;
			var workTarget = functionInfo.target;
			var isHidden = functionInfo.isHidden;
			var isActivity = functionInfo.isActivity;
			var navDesc = functionInfo.desc;
			var appid = functionInfo.appId;
			var notifier = functionInfo.notifier;
			var orderIndex = functionInfo.orderIndex;
			var ext1 = functionInfo.ext1;
			var ext2 = functionInfo.ext2;
			var ext3 = functionInfo.ext3;
			var ext4 = functionInfo.ext4;
			var ext5 = functionInfo.ext5;
			if (id != "" && appid == "") {
				that.$message({ type: 'warning', message: '请设置归属应用' });
				return false;
			}
			that.saveBtnIsDisabled = true;
			let data = {
				url: 'jd',
				data: {
					cmd: 'CONSOLE_P_NAV_DESIGN_FUNCTION_SAVE',
					sid: settingParam.sessionId,
					functionId: id,
					systemId: systemId,
					directoryId: directoryId,
					functionName: functionName,
					icon16: icon16,
					icon64: icon64,
					icon96: icon96,
					functionUrl: linkUrl,
					workTarget: workTarget,
					isHidden: isHidden,
					isActivity: isActivity,
					navDesc: navDesc,
					appid: appid,
					notifier: notifier,
					orderIndex: orderIndex,
					ext1: ext1,
					ext2: ext2,
					ext3: ext3,
					ext4: ext4,
					ext5: ext5,
				}
			};
		},
		treeNodeEnter(data) {
			let that = this;
			if (data.type != undefined) {
				//data.showNodeOp = true;
				setTimeout(() => {
					data.showNodeOp = true;
				}, 100);
			}
			this.hideNavigationDataOpVisiable();
		},
		treeNodeLeave(data) {
			let that = this;
			that.powerUserDarwer = false;
		},
	tableRowClassName({ row, rowIndex }) {
		if (!row.canVisit) {
			return 'warning-row';
		}
		return '';
	},
	deleteNav(data) {
		let $this = this;
		let that = this;
		that.hideNodeOpVisiable(data);
		let hasLeaf = that.currentNodeHasChildren;
		var msg = that.warningInfo[0];
		msg += hasLeaf ? that.warningInfo[1] : "";
		that.$confirm(msg, that.confirmTitle, {
			confirmButtonText: that.confirmOk,
			cancelButtonText: that.confirmCancel,
			type: 'warning'
		}).then(() => {
			that.doDeleteNav();
		}).catch(() => {
			//that.$message({type: 'info', message: '已取消'});
		});
	},
	doDeleteNav() {
		let $this = this;
		let that = this;
		let data = {
			url: 'jd',
			data: {
				cmd: 'CONSOLE_P_NAV_DESIGN_DELETE',
				sid: settingParam.sessionId,
				naviid: that.currentNodeId,
			}
		};
	},
	chargeIsFirst() {
	},
	chargeIsEnd() {
	},
	handleDragStart(node, ev) {
		// return
		// this.treeExpandData = []; // 移除这行，避免拖拽时收起所有节点
		// 深度克隆当前节点数据而非整棵树
		this.dragNodeData = JSON.parse(JSON.stringify(node.data));
		this.sourceParentNode = node.parent;

		// 添加拖拽标记
		this.isDragging = true;

		if (ev.srcElement) {
			ev.srcElement.className += ' is-draging';
		}

	},
	handleDragEnter(draggingNode, dropNode, ev) {
		//拖拽进入其他节点时触发的事件
		if (dropNode && dropNode.data.label !== '加载更多') {
			// 添加拖拽进入的视觉反馈
			const el = ev.currentTarget;
			if (el) {
				el.classList.add('is-drop-inner');
			}
		}
	},
	handleDragLeave(draggingNode, dropNode, ev) {
		//拖拽离开某个节点时触发的事件
		if (dropNode && dropNode.data.label !== '加载更多') {
			// 移除拖拽进入的视觉反馈
			const el = ev.currentTarget;
			if (el) {
				el.classList.remove('is-drop-inner', 'is-drop-prev', 'is-drop-next');
			}
		}
	},
	handleDragOver(draggingNode, dropNode, ev) {
		//在拖拽节点时触发的事件（类似浏览器的 mouseover 事件）
		if (dropNode && dropNode.data.label !== '加载更多') {
			// 根据鼠标位置判断是放在前面、后面还是内部
			const el = ev.currentTarget;
			if (el) {
				const rect = el.getBoundingClientRect();
				const mouseY = ev.clientY;
				const relativeY = mouseY - rect.top;
				const height = rect.height;

				// 清除所有拖拽样式
				el.classList.remove('is-drop-inner', 'is-drop-prev', 'is-drop-next');

				// 根据鼠标位置添加对应样式
				if (relativeY < height * 0.25) {
					el.classList.add('is-drop-prev');
				} else if (relativeY > height * 0.75) {
					el.classList.add('is-drop-next');
				} else {
					el.classList.add('is-drop-inner');
				}
			}
		}
	},
	async handleDragEnd(draggingNode, dropNode, dropType, ev) {
		//拖拽结束时（可能未成功）触发的事件
		//draggingNode.data.isDraging = false;
		// 拖拽结束，重置拖拽状态
		this.isDragging = false;
		let target = ev.toElement != undefined ? ev.toElement : ev.target;
		if (target != undefined) {
			if (target.className.indexOf("is-draging") != -1) {
				target.className = target.className.replace("is-draging", "")
			}
		} else {
			console.log("ev.toElement is undefined");
		}

		// 检查是否有待确认的拖拽操作
		if (this.pendingDragOperation && !this.isWaitingForConfirmation) {
			this.isWaitingForConfirmation = true;
			const operation = this.pendingDragOperation;

			try {
				console.log('handleDragEnd: 弹出确认对话框');
				// 弹出确认对话框
				await this.$confirm(this.warningInfo[2], this.confirmTitle, {
					confirmButtonText: this.confirmOk,
					cancelButtonText: this.confirmCancel,
					type: 'warning'
				});

				// 用户确认，执行拖拽操作
				console.log('handleDragEnd: 用户确认，执行拖拽操作');
				await this.performDragOperation(operation);

			} catch (error) {
				console.log('handleDragEnd: 用户取消拖拽操作');
				// 用户取消，不执行任何操作
			} finally {
				// 清理状态
				this.pendingDragOperation = null;
				this.isWaitingForConfirmation = false;
			}
		}

		// 重置标记
		this.dropSuccess = false;
	},
	handleLoadMoreClick(node, data) {
		// 获取父节点
		const parentNode = node.parent;
		// 手动调用 loadNode 方法加载更多子节点
		this.loadNode(node, (children) => {
			// 更新树视图
			if (Array.isArray(children) && children.length > 0) {
				// 处理加载的节点...
				const parentId = parentNode.data.id;
				this.$refs.navTree.updateKeyChildren(parentId, children);
			}
		});
	},
	//处理节点拖拽完成事件
	async handleDrop(draggingNode, dropNode, dropType, ev) {
		//拖拽成功完成时触发的事件

		if (draggingNode.data.id == 'root') {// 防止拖拽根节点
			return false;
		}

		// 不允许拖拽 "加载更多" 节点
		if (draggingNode.data.label === '加载更多' || dropNode.data.label === '加载更多') {
			console.log('不允许拖拽"加载更多"节点');
			return false;
		}

		// 转换拖拽类型
		var point = dropType;
		if (dropType == undefined) {
			point = "append";
		}
		if (dropType == "after") {
			point = "below";
		}
		if (dropType == "before") {
			point = "above";
		}
		if (dropType == "inner") {
			point = "append";
		}

		// 阻止默认的拖拽行为，我们需要先询问用户确认
		try {
			// 显示确认对话框 - 在操作之前询问用户
			await this.$confirm(this.warningInfo[2], this.confirmTitle, {
				confirmButtonText: this.confirmOk,
				cancelButtonText: this.confirmCancel,
				type: 'warning'
			});

			// 用户确认后，手动处理拖拽逻辑
			this.dropSuccess = true;

			// 对于 inner 类型的拖拽，先处理目标节点的展开和叶子节点转换
			if (dropType === 'inner') {

				// 如果目标节点是叶子节点，转换为非叶子节点
				if (dropNode.data.isLeaf === true) {
					dropNode.data.isLeaf = false;
				}

			}

			// 执行拖拽处理
			await this.dragTreeNode(draggingNode.data, dropNode.data, point);

			// 返回 false 阻止 el-tree 的默认处理，因为我们已经手动处理了
			return false;

		} catch (error) {
			console.log("拖拽操作被用户取消:", error);

			// 用户取消操作，返回 false 阻止拖拽
			// el-tree 会自动将节点恢复到原位置
			return false;
		}
	},
	allowDrop(draggingNode, dropNode, type) {
		// 基本验证
		if (!draggingNode || !dropNode || !draggingNode.data || !dropNode.data) {
			return false;
		}

		// 不允许拖拽到自己
		if (draggingNode.data.id === dropNode.data.id) {
			return false;
		}

		// 不允许拖拽到自己的子节点
		if (this.isDescendant(draggingNode, dropNode)) {
			return false;
		}

		// 根节点不允许被拖拽
		if (draggingNode.data.id === 'root') {
			return false;
		}

		// 不允许拖拽 "加载更多" 节点
		if (draggingNode.data.label === '加载更多' || dropNode.data.label === '加载更多') {
			return false;
		}

		// 保存拖拽意图，但始终返回 false 阻止默认拖拽行为
		this.pendingDragOperation = {
			draggingNode: draggingNode,
			dropNode: dropNode,
			dropType: type
		};

		// 始终返回 false，阻止 el-tree 的默认拖拽行为
		return false;
	},
	allowDrag(draggingNode) {
		// 确保有数据
		if (!draggingNode || !draggingNode.data) {
			return false;
		}

		// 不允许拖拽根节点
		if (draggingNode.data.id === 'root') {
			return false;
		}

		// 不允许拖拽 "加载更多" 节点 - 加强检查
		// if (draggingNode.data.label === '加载更多' || 
		// 	draggingNode.data.id && draggingNode.data.id.includes('load-more')) {
		// 	console.log('allowDrag: 不允许拖拽加载更多节点', draggingNode.data);
		// 	return false;
		// }

		// 检查权限
		if (!this.handleRoot && !draggingNode.data.hasManagerAC) {
			return false;
		}

		return true;
	},
	dragTreeNode(source, target, type) {
		let that = this;
		let tNode = target.id;
		let sNode = source.id;
		let point = type;

		// 确保 sNode 和 tNode 是字符串
		let sNodeStr = String(sNode);
		let tNodeStr = String(tNode);
		let sNodeType = sNodeStr.substring(0, 1);
		let tNodeType = tNodeStr.substring(0, 1);

		that.loading = true;

		// 返回 Promise 以支持 async/await
		return new Promise((resolve, reject) => {
			// 模拟API调用
			setTimeout(() => {
				try {
					that.loading = false;
					that.$message({ type: 'success', message: that.moveSuccess });

				if (point === "append") {

					// 保存源节点的原父节点ID（在更新之前）
					const originalSourceParentId = that.nodeParentMap[String(source.id)] || that.nodeParentMap[source.id] || 'root';

					// 更新 realTreeData 状态
					// 修改被拖拽节点的父节点 - 确保类型一致
					that.nodeParentMap[String(source.id)] = String(target.id);
					
					// 同时更新数字键（为了兼容性）
					that.nodeParentMap[source.id] = target.id;

					// 如果目标节点是叶子节点，转换为非叶子节点
					if (that.realTreeData[target.id] && that.realTreeData[target.id].isLeaf === true) {
						that.realTreeData[target.id].isLeaf = false;
					}

					// 完全避免重新渲染的直接数据操作策略
					that.$nextTick(() => {
						
						// 获取相关节点
						const targetNode = that.$refs.navTree ? that.$refs.navTree.getNode(target.id) : null;
						const sourceOriginalParentNode = that.$refs.navTree ? that.$refs.navTree.getNode(originalSourceParentId) : null;
						
						// 保存目标节点的展开状态
						const targetWasExpanded = targetNode ? targetNode.expanded : false;
						const sourceParentWasExpanded = sourceOriginalParentNode ? sourceOriginalParentNode.expanded : false;
						
						
						// 使用计数器来确保所有更新完成后再处理展开
						let updateCount = 0;
						let completedUpdates = 0;
						
						const checkAllUpdatesComplete = () => {
							completedUpdates++;
							if (completedUpdates === updateCount) {
								
								// 延迟处理展开，确保DOM更新完成
								setTimeout(() => {
									// 只有当目标节点原本就是展开状态时才恢复展开，保持原有的展开/收起状态
									if (targetNode && !targetNode.isLeaf && targetWasExpanded) {
										targetNode.expand();
									}
									
									// 确保源节点的原父节点保持展开状态
									if (sourceOriginalParentNode && sourceParentWasExpanded && !sourceOriginalParentNode.expanded) {
										sourceOriginalParentNode.expand();
									}
									
									// 确保所有父级节点也已展开
									that.ensureParentNodesExpanded(target.id);
								}, 100);
							}
						};
						
						// 更新源节点的原父节点（移除源节点）
						if (originalSourceParentId === 'root') {
							updateCount++;
							// 对于根节点，使用专门的方法处理状态保存和恢复
							that.updateRootNodeWithStateRestore().then(() => {
								checkAllUpdatesComplete();
							});
						} else if (sourceOriginalParentNode) {
							updateCount++;
							// 重新加载原父节点的子节点数据
							that.loadNode(sourceOriginalParentNode, (updatedChildren) => {
								// 使用直接更新方式，保持展开状态
								that.updateNodeDirectly(sourceOriginalParentNode, updatedChildren);
								
								// 确保原父节点保持展开状态
								if (sourceParentWasExpanded && !sourceOriginalParentNode.expanded) {
									setTimeout(() => {
										sourceOriginalParentNode.expand();
									}, 50);
								}
								
								checkAllUpdatesComplete();
							});
						}
						
						// 更新目标节点（添加源节点）
						if (targetNode) {
							updateCount++;
							
							// 重新加载目标节点的子节点数据
							that.loadNode(targetNode, (newChildren) => {
								
								// 使用直接更新方式，保持展开状态
								that.updateNodeDirectly(targetNode, newChildren);
								
								// 确保目标节点保持展开状态
								if (!targetNode.isLeaf && (!targetNode.expanded || targetWasExpanded)) {
									setTimeout(() => {
										targetNode.expand();
									}, 50);
								}
								
								checkAllUpdatesComplete();
							});
						} else if (target.id && String(target.id).startsWith('1')) {
							// 如果目标节点是根级节点但找不到节点对象，更新根数据
							updateCount++;
							
							// 收集当前展开的节点ID
							const expandedNodeIds = [];
							if (that.$refs.navTree && that.$refs.navTree.root) {
								const collectExpanded = (nodes) => {
									nodes.forEach(node => {
										if (node.expanded) {
											expandedNodeIds.push(node.data.id);
										}
										if (node.childNodes && node.childNodes.length > 0) {
											collectExpanded(node.childNodes);
										}
									});
								};
								collectExpanded(that.$refs.navTree.root.childNodes);
							}
							
							that.loadNode({ level: 0 }, (children) => {
								if (children) {
									that.naviagtionTreeData = children;
									
									// 立即恢复展开状态
									that.$nextTick(() => {
										expandedNodeIds.forEach(nodeId => {
											const node = that.$refs.navTree ? that.$refs.navTree.getNode(nodeId) : null;
											if (node && !node.expanded && !node.isLeaf) {
												console.log('dragTreeNode append: 恢复展开状态', nodeId);
												node.expand();
											}
										});
									});
								}
								checkAllUpdatesComplete();
							});
						}
						
						// 如果没有需要更新的节点，直接完成
						if (updateCount === 0) {
							setTimeout(() => {
								that.ensureParentNodesExpanded(target.id);
							}, 100);
						}
					});
				} else if (point === "before" || point === "after" || point === "above" || point === "below") {
					
					// 保存源节点的原父节点ID（在更新之前）
					const originalSourceParentId = that.nodeParentMap[String(source.id)] || that.nodeParentMap[source.id] || 'root';
					
					// 获取目标节点的父节点ID
					const targetParentId = that.nodeParentMap[target.id] || that.nodeParentMap[Number(target.id)] || 'root';
					
					// 更新被拖拽节点的父节点为目标节点的父节点
					that.nodeParentMap[String(source.id)] = targetParentId;
					that.nodeParentMap[source.id] = targetParentId;
					
					// 实现同级排序：调整节点顺序
					// 创建一个临时的节点排序映射
					if (!that.nodeOrder) {
						that.nodeOrder = {};
					}
					
					// 获取当前同级所有节点
					const siblingNodes = [];
					
					console.log(`dragTreeNode: 查找父节点 ${targetParentId} 的所有子节点`);
					console.log(`dragTreeNode: 当前 realTreeData:`, that.realTreeData);
					console.log(`dragTreeNode: 当前 nodeParentMap:`, that.nodeParentMap);
					
					for (const nodeId in that.realTreeData) {
						const nodeData = that.realTreeData[nodeId];
						let nodeParentId = that.nodeParentMap[nodeId] || that.nodeParentMap[Number(nodeId)] || 'root';
						
						console.log(`dragTreeNode: 检查节点 ${nodeId}，父节点: ${nodeParentId}`);
						
						if (String(nodeParentId) === String(targetParentId)) {
							console.log(`dragTreeNode: 节点 ${nodeId} 属于父节点 ${targetParentId}，添加到同级节点列表`);
							siblingNodes.push({
								id: nodeData.id,
								label: nodeData.label,
								isLeaf: nodeData.isLeaf,
								allowDrag: nodeData.allowDrag,
								total: nodeData.total,
							});
						}
					}
					
					console.log(`dragTreeNode: 找到 ${siblingNodes.length} 个同级节点:`, siblingNodes.map(n => n.id));
					
					// 找到源节点和目标节点在同级中的位置
					const sourceIndex = siblingNodes.findIndex(node => String(node.id) === String(source.id));
					const targetIndex = siblingNodes.findIndex(node => String(node.id) === String(target.id));
					
					console.log(`dragTreeNode: 同级排序 - 源节点 ${source.id} 索引: ${sourceIndex}, 目标节点 ${target.id} 索引: ${targetIndex}`);
					console.log(`dragTreeNode: 同级排序 - 拖拽类型: ${point}`);
					
					if (sourceIndex !== -1 && targetIndex !== -1) {
						// 从原位置移除源节点
						const sourceNode = siblingNodes.splice(sourceIndex, 1)[0];
						
						// 计算新的插入位置
						let newIndex;
						if (point === "before" || point === "above") {
							newIndex = targetIndex > sourceIndex ? targetIndex - 1 : targetIndex;
						} else if (point === "after" || point === "below") {
							newIndex = targetIndex >= sourceIndex ? targetIndex : targetIndex + 1;
						} else {
							// 默认情况，当作 after 处理
							newIndex = targetIndex >= sourceIndex ? targetIndex : targetIndex + 1;
						}
						
						console.log(`dragTreeNode: 同级排序 - 计算新位置: ${newIndex}`);
						
						// 插入到新位置
						siblingNodes.splice(newIndex, 0, sourceNode);
						
						console.log(`dragTreeNode: 同级排序 - 重新排序后的节点顺序:`, siblingNodes.map(n => n.id));
						
						// 更新节点顺序映射
						siblingNodes.forEach((node, index) => {
							that.nodeOrder[String(node.id)] = index;
						});
						
						console.log(`dragTreeNode: 同级排序 - 更新后的 nodeOrder:`, that.nodeOrder);
					}
								// 精确更新同级排序，避免全树重新渲染
					that.$nextTick(() => {
						
						// 如果源节点和目标节点不在同一个父节点下，需要更新两个父节点
						if (originalSourceParentId !== targetParentId) {
								
								// 更新原父节点的子节点（移除源节点）
								if (originalSourceParentId === 'root') {
									// 对于根节点，使用状态保存和恢复
									that.updateRootNodeWithStateRestore();
								} else {
									const originalParentNode = that.$refs.navTree ? that.$refs.navTree.getNode(originalSourceParentId) : null;
									if (originalParentNode) {
										// 保存原父节点的展开状态
										const wasOriginalParentExpanded = originalParentNode.expanded;
										
										that.loadNode(originalParentNode, (updatedChildren) => {
											that.updateNodeDirectly(originalParentNode, updatedChildren);
											
											// 确保原父节点保持展开状态
											if (wasOriginalParentExpanded && !originalParentNode.expanded) {
												setTimeout(() => {
													originalParentNode.expand();
												}, 50);
											}
										});
									}
								}
								
								// 更新新父节点的子节点（添加源节点）
								if (targetParentId === 'root') {
									// 对于根节点，使用状态保存和恢复
									that.updateRootNodeWithStateRestore();
								} else {
									const targetParentNode = that.$refs.navTree ? that.$refs.navTree.getNode(targetParentId) : null;
									if (targetParentNode) {
										// 保存目标父节点的展开状态
										const wasTargetParentExpanded = targetParentNode.expanded;
										
										that.loadNode(targetParentNode, (newChildren) => {
											that.updateNodeDirectly(targetParentNode, newChildren);
											
											// 确保目标父节点保持展开状态
											if (wasTargetParentExpanded && !targetParentNode.expanded) {
												setTimeout(() => {
													targetParentNode.expand();
												}, 50);
											}
										});
									}
								}
							} else {
								
								// 如果目标节点的父节点是根节点，更新根节点数据
								if (targetParentId === 'root') {
									// 对于根节点，使用状态保存和恢复
									that.updateRootNodeWithStateRestore();
								} else {
									// 如果目标节点的父节点不是根节点，只更新父节点的子节点
									const parentNode = that.$refs.navTree ? that.$refs.navTree.getNode(targetParentId) : null;
									if (parentNode) {
										
										// 保存父节点的展开状态
										const wasParentExpanded = parentNode.expanded;
										
										// 重新加载父节点的子节点数据
										that.loadNode(parentNode, (newChildren) => {
											if (newChildren) {
												// 使用直接更新方式，保持展开状态
												that.updateNodeDirectly(parentNode, newChildren);
												
												// 确保父节点保持展开状态
												if (wasParentExpanded && !parentNode.expanded) {
													setTimeout(() => {
														parentNode.expand();
													}, 50);
												}
											}
										});
									} else {
										// 备用方案：跳过根节点更新
										console.log('同级排序：跳过根节点更新');
									}
								}
							}
						});
				} else {
					console.log('dragTreeNode: 未知的拖拽类型:', point);
				}

					that.dropSuccess = true;
					console.log('dragTreeNode 完成');
					resolve(); // 成功时调用 resolve
				} catch (error) {
					console.error("拖拽处理出错:", error);
					that.$message({ type: 'error', message: '操作失败，请重试' });

					// 在错误情况下恢复节点
					const draggingTreeNode = that.$refs.navTree.getNode(source.id);
					if (draggingTreeNode && that.sourceParentNode) {
						that.recoverDraggedNode(draggingTreeNode, that.sourceParentNode);
					}
					reject(error); // 失败时调用 reject
				} finally {
					that.loading = false;
				}
			}, 500);
		});
	},
	recoverDraggedNode(draggingNode, sourceParentNode) {
		// 恢复被拖拽的节点到原始位置
		if (sourceParentNode && sourceParentNode.data) {
			const sourceParentId = sourceParentNode.data.id;
			if (sourceParentId) {
				// 重新加载父节点的子节点
				this.$refs.navTree.updateKeyChildren(sourceParentId, []);
				const loadedNode = this.$refs.navTree.getNode(sourceParentId);
				if (loadedNode) {
					this.loadNode(loadedNode, (children) => {
						this.$refs.navTree.updateKeyChildren(sourceParentId, children);
					});
				}
			}
		}
	},
	// 添加一个新方法，用于在不丢失数据的情况下更新节点
	updateNodeWithoutDataLoss(nodeId) {
		const that = this;
		// 获取当前节点
		const currentNode = that.$refs.navTree.getNode(nodeId);

		if (!currentNode) return;

		// 展开节点以确保子节点可见
		if (!currentNode.expanded) {
			currentNode.expand();
		}

		// 获取子节点的展开状态
		const expandedChildIds = [];
		if (currentNode.childNodes) {
			currentNode.childNodes.forEach(child => {
				if (child.expanded) {
					expandedChildIds.push(child.data.id);
				}
			});
		}

		// 使用 API 获取最新数据并更新
		// 注意：这里使用模拟数据，实际应调用后端API
		setTimeout(() => {
			// 假设这是从服务器获取的新数据
			const newChildren = currentNode.data.children ?
				[...currentNode.data.children] :
				[{ id: `${nodeId}-1`, label: '新节点1', isLeaf: false }];

			// 使用 updateKeyChildren 更新子节点
			that.$refs.navTree.updateKeyChildren(nodeId, newChildren);

			// 恢复展开状态
			that.$nextTick(() => {
				expandedChildIds.forEach(id => {
					const node = that.$refs.navTree.getNode(id);
					if (node) node.expand();
				});
			});
		}, 100);
	},
	
	// 处理节点位置移动
	moveTreeNode(nodeData, type) {
		console.log(nodeData, type, '移动');

		let $this = this;
		let that = this;
		if (that.isMoving) {
			//上移下移处理重复点击
			return false;
		}
		that.isMoving = true;
		let tNode = "";
		if (type == "above" && nodeData.isFirst) {
			return false;
		}
		if (type == "below" && nodeData.isEnd) {
			return false;
		}
		if (type == "above") {
			tNode = nodeData.prevNodeId;
		}
		if (type == "below") {
			tNode = nodeData.nextNodeId;
		}

		let sNode = that.currentNodeId;
		let point = type;
		that.loading = true;
		let pid = nodeData.id;
		that.loadSystemData();//如果是子系统的上移下移 刷新整个子系统
	},
	nodeNameChargeChange() {
		if (this.currentNodeName == "") {
			this.currentNodeName = this.oldBlurName;
			this.$message({ type: 'warning', message: this.nodeMessage[0] });
			return false;
		}

		if (this.currentNodeName != this.oldBlurName) {
			this.navSaveAttributeData("info");
		}
	},
	nodeSortChargeChange(dataP) {
		let $this = this;
		let that = this;
		if (that.currentNodeSort == "") {
			that.currentNodeSort = this.oldBlurSort;
			that.$message({ type: 'warning', message: that.nodeMessage[1] });
			dataP.opPopVisible = true;
			that.doNotCloseOpPop = true;
			return false;
		}
		//smallint(3) 32767
		if (that.currentNodeSort != "" && parseInt(that.currentNodeSort) > 30000) {
			that.currentNodeSort = this.oldBlurSort;
			that.$message({ type: 'warning', message: that.nodeMessage[2] });
			dataP.opPopVisible = true;
			that.doNotCloseOpPop = true;
			return false;
		}
		if (that.currentNodeSort != that.oldBlurSort) {
			let array = [];
			let json = {
				id: that.currentNodeId,
				orderIndex: that.currentNodeSort
			};
			array.push(json);
			let navIndexArr = JSON.stringify(array);
			that.loading = true;
			let data = {
				url: 'jd',
				data: {
					cmd: 'CONSOLE_P_NAV_DESIGN_TREENODE_SAVE_ORDERINDEX',
					sid: settingParam.sessionId,
					navIndexArr: navIndexArr,
				}
			};
		}
	},
	navSaveAttributeData(type) {
		//type info (name icon) type active (是否可见)
		let $this = this;
		let that = this;
		let isActivity = this.currentNodeVisiable;
		let orderIndex = this.currentNodeSort;
		let name = this.currentNodeName;
		let icon16 = this.currentIcon16;
		that.loading = true;
		let data = {
			url: 'jd',
			data: {
				cmd: 'CONSOLE_P_NAV_SAVE_ATTRIBUTE_DATA',
				sid: settingParam.sessionId,
				type: "",
				id: that.currentNodeId,
				name: name,
				isActivity: isActivity,
				orderIndex: orderIndex,
			}
		};
		if (type != "active") {
			data.data.icon16 = icon16;
		}
	},
	changeNavVisiableForLabel(data) {
		if (!this.isHighSecurity) {
			if (!data.hasManagerAC) {
				return false;
			}
		} else {
			if (!this.isSecurityMaster) {
				return false;
			}
		}

		//bug 2020 开关通栏点击
		let $this = this;
		let that = this;
		that.opNodeVisiable = !that.opNodeVisiable;
		that.currentNodeVisiable = that.opNodeVisiable;
		that.navSaveAttributeData("active");
	},
	changeNavVisiable(data) {
		if (!this.isHighSecurity) {
			//没开启三员时，根据正常的操作权限走 没权限的不可操作前台是否可见
			if (!data.hasManagerAC) {
				return false;
			}
		} else {
			//开启三员时，如果非安全保密管理员用户 则不能操作前台是否可见
			if (!this.isSecurityMaster) {
				return false;
			}
		}
		let $this = this;
		let that = this;
		console.log(that.opNodeVisiable);
		that.currentNodeVisiable = that.opNodeVisiable;
		that.navSaveAttributeData("active");
	},
	navSystemAuth(data, accessMode) {
		let $this = this;
		let that = this;
		let accessModeScope = "";
		if (accessMode == "0") {
			accessModeScope = "[0]";
		} else {
			accessModeScope = "[2]";
		}
		that.hideNodeOpVisiable(data);
		let id = that.currentNodeId;
		if (id.length > 2 && id.indexOf('s_') == 0) {
			id = id.substr(2);
			that.AWSUI.openAc({
				sid: settingParam.sessionId,
				title: that.subAdminTitle,
				width: 900,
				resourceId: id,
				resourceType: 'platform.navAdmin',
				assignmentTypes: 'company,department,user,position,role,team',
				groupType: "",
				permissionType: '',
				accessModeScope: accessModeScope,
				callback: (list) => {
					//变成已设置 无
					console.log(list);
					if (list.length > 0) {
						list.forEach(function (eachList, i) {
							if (eachList.accessMode == 0) {
								that.naviagtionTreeData.forEach(function (item, n) {
									if (item.id == that.currentNodeId) {
										if (eachList.acList.length > 0) {
											item.canManageSize = eachList.acList.length;
										} else {
											item.canManageSize = 0;
										}
									}
								});
							} else if (eachList.accessMode == 2) {
								that.naviagtionTreeData.forEach(function (item, n) {
									if (item.id == that.currentNodeId) {
										if (eachList.acList.length > 0) {
											item.canVisitSize = eachList.acList.length;
										} else {
											item.canVisitSize = 0;
										}
									}
								});
							}
						});
					} else {
						that.naviagtionTreeData.forEach(function (item, n) {
							if (item.id == that.currentNodeId) {
								item.canManageSize = 0;
								item.canVisitSize = 0;
							}
						});
					}


				}
			})
		} else {
			that.$message({ type: 'warning', message: '只能对子系统授权' });
		}
	},
	updateIconPickerOption(data) {
		let $this = this;
		let that = this;
		let iconValueOb = { "icon": data.iconFont.code, "color": data.iconFont.color };
		//that.defaultIconPickerOptions.icon = iconValueOb.icon;
		//that.defaultIconPickerOptions.color = iconValueOb.color;
		if (data.icon16Original == "") {
			that.iconColors.icon = "";
			that.iconColors.color = "";
		} else {
			that.iconColors.icon = iconValueOb.icon;
			that.iconColors.color = iconValueOb.color;
		}
		that.defaultIconPickerOptions.show = true;
		that.reloadIconPicker(data);
	},
	resetIconPickerOption(data) {
		let $this = this;
		let that = this;
		//that.defaultIconPickerOptions.icon = "";
		//that.defaultIconPickerOptions.color = "";
		that.iconColors.icon = "";
		that.iconColors.color = "";
		that.defaultIconPickerOptions.show = true;
		that.reloadIconPicker(data);
	},
	reloadIconPicker(data) {
		// 移除组件
		data.updateIconPicker = false;
		// 在组件移除后，重新渲染组件
		// this.$nextTick可实现在DOM 状态更新后，执行传入的方法。
		this.$nextTick(() => {
			data.updateIconPicker = true;
		});
	},
	chargeIsIconFont(icon16) {
		let flag = icon16.startsWith("&#");
		if (!flag) {
			let index = icon16.indexOf("|#");
			if (index == 1) {
				flag = true;
			}
		}
		return flag;
	},
	getIconFontCode(isIconFont, icon16) {
		if (isIconFont) {
			let str = icon16;
			let ind = str.indexOf("|");
			if (ind > 0) {
				return str.substring(0, ind);
			} else {
				return str;
			}
		} else {
			return "";
		}
	},
	getIconFontColor(isIconFont, icon16) {
		if (isIconFont) {
			let str = icon16;
			let ind = str.indexOf("|");
			if (ind > 0) {
				return str.substring(ind + 1);
			} else {
				return "";
			}
		} else {
			return "";
		}
	},
	// 检查 nodeA 是否为 nodeB 的子孙节点
	isDescendant(nodeA, nodeB) {
		if (!nodeA || !nodeB || !nodeA.data || !nodeB.data) {
			return false;
		}

		// 遍历 nodeA 的所有父节点
		let currentNode = nodeA.parent;
		while (currentNode) {
			if (currentNode.data.id === nodeB.data.id) {
				return true;
			}
			currentNode = currentNode.parent;
		}
		return false;
	},
	// 执行拖拽操作的方法
	async performDragOperation(operation) {

		if (!operation || !operation.draggingNode || !operation.dropNode) {
			throw new Error('拖拽操作参数不完整');
		}

		const { draggingNode, dropNode, dropType } = operation;

		// 智能拖拽意图判断：如果是 next/after 类型，询问用户是否想要放入目标节点内部
		let finalDropType = dropType;
		// 转换拖拽类型
		let point = finalDropType;
		if (finalDropType === "after") {
			point = "below";
		}
		if (finalDropType === "before") {
			point = "above";
		}
		if (finalDropType === "inner") {
			point = "append";
		}
		if (finalDropType === "next") {
			point = "after";
		}


		// 对于 inner 类型的拖拽，预处理目标节点
		if (finalDropType === 'inner') {
			console.log('performDragOperation: 处理 inner 类型拖拽');

			// 如果目标节点是叶子节点，转换为非叶子节点
			if (dropNode.data.isLeaf === true) {
				console.log('performDragOperation: 目标节点是叶子节点，转换为非叶子节点');
				dropNode.data.isLeaf = false;
			}
			
			// 注意：不在这里展开节点，由 dragTreeNode 统一处理展开逻辑
		}

		// 执行实际的拖拽操作
		try {
			await this.dragTreeNode(draggingNode.data, dropNode.data, point);
			console.log('performDragOperation: 拖拽操作完成');

		} catch (error) {
			console.error('performDragOperation: 拖拽操作失败', error);
			throw error;
		}
	},
	// 恢复展开状态
	restoreExpandedState(expandedKeys) {
		console.log('restoreExpandedState: 开始恢复展开状态', expandedKeys);
		
		if (!expandedKeys || expandedKeys.length === 0) {
			console.log('restoreExpandedState: 没有需要恢复的展开状态');
			return;
		}
		
		// 延迟恢复，确保DOM已更新
		setTimeout(() => {
			expandedKeys.forEach(nodeId => {
				const node = this.$refs.navTree ? this.$refs.navTree.getNode(nodeId) : null;
				if (node && !node.expanded && !node.isLeaf) {
					console.log('restoreExpandedState: 恢复节点展开状态', nodeId);
					node.expand();
				}
			});
		}, 100);
	},
	
	// 确保目标节点的所有父级节点都已展开（修复深层拖拽问题）- 最终版
	ensureParentNodesExpanded(nodeId) {
		console.log('ensureParentNodesExpanded: 开始确保父级节点展开，目标节点:', nodeId);
		
		// 获取父级节点ID路径
		const parentIds = [];
		let currentId = nodeId;
		let depth = 0;
		const maxDepth = 10; // 防止无限循环
		
		// 向上遍历找到所有父级节点
		while (currentId && depth < maxDepth) {
			const parentId = this.nodeParentMap[currentId] || this.nodeParentMap[Number(currentId)];
			if (parentId && parentId !== 'root') {
				parentIds.unshift(parentId); // 添加到数组开头，保证从根向下的顺序
				currentId = parentId;
				depth++;
			} else {
				break;
			}
		}
		
		console.log('ensureParentNodesExpanded: 父级节点路径:', parentIds);
		
		// 创建展开任务队列，只处理父级节点的展开
		const expandTasks = [];
		
		// 只添加父级节点展开任务，不包括目标节点本身
		parentIds.forEach((parentId, index) => {
			expandTasks.push({
				nodeId: parentId,
				isTarget: false,
				delay: index * 200 // 逐级展开，每级延迟200ms
			});
		});
		
		// 执行展开任务
		expandTasks.forEach(task => {
			setTimeout(() => {
				const node = this.$refs.navTree ? this.$refs.navTree.getNode(task.nodeId) : null;
				if (node) {
					if (!node.expanded && !node.isLeaf) {
						console.log(`ensureParentNodesExpanded: 展开父级节点 ${task.nodeId}`);
						node.expand();
						
						// 如果节点需要加载子节点，等待加载完成
						if (!node.loaded) {
							const checkLoaded = () => {
								if (node.loaded) {
									console.log(`ensureParentNodesExpanded: 节点 ${task.nodeId} 加载完成`);
								} else {
									setTimeout(checkLoaded, 100);
								}
							};
							checkLoaded();
						}
					} else if (node.expanded) {
						console.log(`ensureParentNodesExpanded: 节点 ${task.nodeId} 已展开`);
					} else {
						console.log(`ensureParentNodesExpanded: 节点 ${task.nodeId} 是叶子节点`);
					}
				} else {
					console.warn(`ensureParentNodesExpanded: 未找到节点 ${task.nodeId}`);
				}
			}, task.delay);
		});
		
		// 在所有展开任务完成后，进行最终验证（只验证父级节点）
		const finalDelay = parentIds.length * 200 + 500;
		setTimeout(() => {
			console.log('ensureParentNodesExpanded: 最终验证父级节点展开状态');
			
			// 只验证父级节点是否都已展开，不强制展开目标节点
			parentIds.forEach(parentId => {
				const parentNode = this.$refs.navTree ? this.$refs.navTree.getNode(parentId) : null;
				if (parentNode && !parentNode.expanded && !parentNode.isLeaf) {
					console.log(`ensureParentNodesExpanded: 最终强制展开父级节点 ${parentId}`);
					parentNode.expand();
				}
			});
		}, finalDelay);
	},
	
	// 递归收集所有展开节点的ID
	collectExpandedNodes(nodes, expandedKeys) {
		if (!nodes || !Array.isArray(nodes)) return;
		
		nodes.forEach(node => {
			if (node.expanded) {
				expandedKeys.push(node.data.id);
				console.log('collectExpandedNodes: 收集展开节点:', node.data.id);
			}
			
			if (node.childNodes && node.childNodes.length > 0) {
				this.collectExpandedNodes(node.childNodes, expandedKeys);
			}
		});
	},
	// 安全地展开指定节点，避免不必要的重新渲染
	safeExpandNode(nodeId, callback) {
		const node = this.$refs.navTree ? this.$refs.navTree.getNode(nodeId) : null;
		if (!node) {
			console.warn('safeExpandNode: 未找到节点', nodeId);
			return;
		}
		
		console.log('safeExpandNode: 展开节点', nodeId, '当前状态:', node.expanded);
		
		// 如果节点已经展开，直接调用回调
		if (node.expanded) {
			console.log('safeExpandNode: 节点已展开，直接调用回调');
			if (callback) callback();
			return;
		}
		
		// 如果节点是叶子节点，不需要展开
		if (node.isLeaf) {
			console.log('safeExpandNode: 节点是叶子节点，不需要展开');
			if (callback) callback();
			return;
		}
		
		// 展开节点
		node.expand();
		
		// 等待展开完成后调用回调
		if (callback) {
			setTimeout(() => {
				console.log('safeExpandNode: 节点展开完成');
				callback();
			}, 100);
		}
	},
	
	// 直接更新节点数据而不触发重新渲染 - 解决拖拽时父节点收起的核心方法
	updateNodeDirectly(node: any, newChildren: any[]) {
		console.log('updateNodeDirectly: 开始直接更新节点', node.data.id, newChildren);
		
		if (!node || !node.store || !node.store.nodesMap) {
			console.warn('updateNodeDirectly: 节点或 store 不存在');
			return;
		}
		
		// 保存节点的展开状态
		const wasExpanded = node.expanded;
		const expandedChildIds: string[] = [];
		
		// 收集当前子节点的展开状态
		if (node.childNodes && node.childNodes.length > 0) {
			node.childNodes.forEach((child: any) => {
				if (child.expanded) {
					expandedChildIds.push(child.data.id);
				}
				// 从 store 中移除旧的子节点
				if (child.data && child.data.id) {
					delete node.store.nodesMap[child.data.id];
				}
			});
		}
		
		console.log('updateNodeDirectly: 保存展开状态', { wasExpanded, expandedChildIds });
		
		// 使用 updateTreeContent 切换强制重新渲染
		console.log('updateNodeDirectly: 使用 updateTreeContent 切换强制重新渲染');
		this.updateTreeContent = false;
		
		// 完全重新设置节点的子节点列表
		console.log('updateNodeDirectly: 重新设置节点子节点列表', node.data.id, newChildren.map((c: any) => c.id));
		
		// 清空现有子节点
		node.childNodes = [];
		node.data.children = [];
		
		// 重新创建并添加子节点
		const newChildNodes = newChildren.map((childData: any) => {
			// 创建新节点
			const childNode = node.store.createNode(childData);
			childNode.parent = node;
			childNode.level = node.level + 1;
			node.store.nodesMap[childData.id] = childNode;
			return childNode;
		});
		
		// 设置新的子节点列表
		node.childNodes = newChildNodes;
		node.data.children = newChildren;
		node.loaded = true;
		
		console.log('updateNodeDirectly: 设置完成，新的子节点顺序:', node.childNodes.map((n: any) => n.data.id));
		
		// 强制更新 DOM
		this.$nextTick(() => {
			// 重新启用树组件
			this.updateTreeContent = true;
			
			this.$nextTick(() => {
				// 恢复父节点的展开状态
				if (wasExpanded && !node.expanded) {
					console.log('updateNodeDirectly: 恢复父节点展开状态');
					node.expand();
				}
				
				// 恢复子节点的展开状态
				expandedChildIds.forEach((childId: string) => {
					const childNode = node.store.nodesMap[childId];
					if (childNode && !childNode.expanded && !childNode.isLeaf) {
						console.log('updateNodeDirectly: 恢复子节点展开状态', childId);
						childNode.expand();
					}
				});
				
				// 使用 Vue 的响应式更新机制
				console.log('updateNodeDirectly: 触发响应式更新');
				
				// 方法1: 直接替换 children 数组以触发响应式更新
				node.data.children = [...newChildren];
				
				// 方法2: 强制更新当前组件
				this.$forceUpdate();
			});
		});
		
		console.log('updateNodeDirectly: 直接更新完成');
	},
	// 专门用于处理根节点的状态保存和恢复
	updateRootNodeWithStateRestore() {
		
		// 收集当前展开的节点ID
		const expandedNodeIds = [];
		if (this.$refs.navTree && this.$refs.navTree.root) {
			const collectExpanded = (nodes) => {
				nodes.forEach(node => {
					if (node.expanded) {
						expandedNodeIds.push(node.data.id);
					}
					if (node.childNodes && node.childNodes.length > 0) {
						collectExpanded(node.childNodes);
					}
				});
			};
			collectExpanded(this.$refs.navTree.root.childNodes);
		}
		
		
		// 返回Promise以支持异步调用
		return new Promise((resolve) => {
			this.loadNode({ level: 0 }, (children) => {
				if (children) {
					this.naviagtionTreeData = children;
					
					// 立即恢复展开状态
					this.$nextTick(() => {
						expandedNodeIds.forEach(nodeId => {
							const node = this.$refs.navTree ? this.$refs.navTree.getNode(nodeId) : null;
							if (node && !node.expanded && !node.isLeaf) {
								node.expand();
							} else if (node) {
							} else {
							}
						});
						resolve();
					});
				} else {
					console.warn('updateRootNodeWithStateRestore: 加载根节点数据失败');
					resolve();
				}
			});
		});
	},
},
// 如果这里有其他属性，请删除这行注释
})
</script>

<style scoped>
.left-navigation-panel {
	/*
		padding:6px 30px 5px 10px;
		*/
	margin-top: -5px;
}

.header {
	padding: 6px 30px 5px 10px;
	height: 35px;
}

.main {
	padding: 0px 5px 10px 5px;
	height: calc(100vh - 35px - 10px - 65px);
	overflow-y: auto;
}


/*树样式开始*/
.custom-tree-node {
	width: 100%;
	height: 26px;
	line-height: 26px;
	border-radius: 5px;
}

/*
	.custom-tree-node:hover {
		background: #ff0000;
	}

	.custom-tree-node.active {
		background: #f8f8f8;
	}
	*/
.custom-tree-node-label {
	width: 125px;
	float: left;
	height: 26px;
	line-height: 26px;
}

.custom-tree-node-label .short {}

.custom-tree-node-label .full {
	width: 210px;
}

.tree-op-panel {
	color: #c0c4cc;
	width: 85px;
	overflow: hidden;
	float: right;
	text-align: right;
	height: 26px;
	margin-top: 0px;
}

.tree-op {
	color: #666;
	cursor: pointer;
	display: inline-block;
	vertical-align: middle;
	font-size: 12px;
	padding: 3px 6px;
	line-height: 12px;
}

.tree-op:hover {
	background-color: #e7eaef;
	border-radius: 4px;
	cursor: pointer;
}

/*树样式结束*/

/**侧边栏**/
.navigation-sidebar-header-title {
	font-size: 16px;
	color: #333;
	font-weight: 700;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.navigation-info-drawer .el-drawer__header,
.navigation-powerUser-drawer .el-drawer__header {
	padding: 16px;
	margin-bottom: 0px;
	font-size: 16px !important;
	color: #333;
	font-weight: 700;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.navigation-info-drawer .el-drawer__title,
.navigation-powerUser-drawer .el-drawer__title {
	font-size: 16px !important;
}

.navigation-info-drawer .el-drawer__body {
	overflow: hidden;
	padding: 0px;
}

.navigation-powerUser-drawer .el-drawer__body {
	overflow: hidden;
}

.el-menu {
	border-right: none;
}

.showsort .el-input__inner {
	padding: 0px 0px 0px 5px !important;
}

/*
	.tree-node-more-panel .el-input__inner {
		padding: 0px 5px !important;
	}
	*/

.more-left-panel .el-input--suffix .el-input__inner {
	padding-right: 30px !important;
	overflow: hidden;
	text-overflow: ellipsis;
}

.el-table__header {
	width: 100% !important;
}

.el-table .warning-row {
	color: red !important;
}

.el-drawer__header> :first-child {
	width: 90%;
	overflow: hidden;
	text-overflow: ellipsis;
}

/*.navigation-tree .el-tree-node.is-current {
		background: #f8f8f8;
	}*/

.navigation-tree .el-tree-node.is-current>.el-tree-node__content {
	background: #f8f8f8;
}

.navigation-tree .el-tree-node__content:hover {
	background: #f8f8f8;
}

/* &#xe785; */
.navigation-tree .el-tree-node.is-draging>.el-tree-node__content:before {
	content: '';
	color: #666;
	size: 12px;
	font-family: "awsui-iconfont";
	content: "\e785";
}

/* 树子节点定高 */
.navigation-tree .el-tree-node .el-tree-node__children {
	overflow: auto !important;
	max-height: 290px !important;
}

.navigation-tree .el-tree-node__content {
	overflow: hidden;
}

/* 改善拖拽体验的样式 */
.navigation-tree .el-tree-node.is-draging {
	opacity: 0.6;
	transform: scale(0.95);
	transition: all 0.2s ease;
}

.navigation-tree .el-tree-node.is-draging>.el-tree-node__content {
	background: #e6f7ff;
	border: 1px dashed #1890ff;
}

.navigation-tree .el-tree-node__content.is-drop-inner {
	background: #f0f9ff;
	border: 2px dashed #1890ff;
}

.navigation-tree .el-tree-node__content.is-drop-prev {
	border-top: 2px solid #1890ff;
}

.navigation-tree .el-tree-node__content.is-drop-next {
	border-bottom: 2px solid #1890ff;
}

/* 拖拽时的光标样式 */
.navigation-tree .el-tree-node[draggable="true"] .custom-tree-node-label {
	cursor: move;
}

/* 拖拽禁用时的样式 */
.navigation-tree .el-tree-node[draggable="false"] .custom-tree-node-label {
	cursor: not-allowed;
}

/* 加载更多节点的特殊样式 */
.navigation-tree .load-more-node {
	color: #1890ff;
	cursor: pointer;
	font-size: 12px;
	padding: 2px 6px;
	border-radius: 4px;
	transition: background-color 0.2s;
}

.navigation-tree .load-more-node:hover {
	background-color: #f0f9ff;
}

/* 节点展开时的动画效果 */
.navigation-tree .el-tree-node__children {
	transition: max-height 0.3s ease-in-out;
}

/* 拖拽高亮效果 */
.navigation-tree .el-tree-node.is-current>.el-tree-node__content {
	background: #f0f9ff;
	border-left: 3px solid #1890ff;
}

/* 提升拖拽区域的点击感知 */
.navigation-tree .el-tree-node__content {
	padding: 5px 0;
	min-height: 32px;
	display: flex;
	align-items: center;
}
</style>
<style lang="less">
.ch-nps-remind-overview {
	div {
		display: flex;
		flex-direction: column;

		.right-down-1.el-dialog {
			display: flex;
			flex-direction: column;
			width: 17.6% !important;
			max-height: 41.4% !important;
			min-width: 281px;
			min-height: 309px;
		}

		.right-down-2.el-dialog {
			display: flex;
			flex-direction: column;
			width: 24% !important;
			max-height: 56.4% !important;
			min-width: 300px;
			min-height: 356px;
		}

		.middle-1.el-dialog {
			display: flex;
			flex-direction: column;
			overflow: hidden;
			width: 37.3% !important;
			max-height: 56.4% !important;
			min-width: 447px;
			min-height: 334px;
		}

		.middle-2.el-dialog {
			display: flex;
			flex-direction: column;
			overflow: hidden;
			width: 80% !important;
			max-height: 90% !important;
			min-width: 460px;
			min-height: 384px;
		}
	}
}

.ch-nps-survey-overview {
	div {
		top: auto !important;
		bottom: 1px !important;

		.ch-nps-survey-dialog {
			display: flex !important;
			flex-direction: column !important;
			margin-right: 0 !important;
			margin-bottom: 0 !important;
			width: 35.4% !important;
			min-width: 449px;
			max-height: calc(50vh + 20px) !important;
			min-height: 25vh !important;
			overflow: hidden !important;
		}
	}
}

.nps .el-overlay .el-overlay-dialog .login-dialog .el-dialog__body .container .right-content .basic-info .basic-main .el-form .el-form-item .el-form-item__content .phone-input .el-input__inner {
	border: none;
}

.nps .el-overlay .el-overlay-dialog .login-dialog .el-dialog__body .container .right-content .details-box .box-main .el-form .el-form-item .el-form-item__content .el-input .el-input__inner {
	box-shadow: none;
}
</style>
